GitHub | 您所在的位置:网站首页 › javascript csv › GitHub |
CSV
CSV is a universal JavaScript CSV parser designed specifically to be simple, fast, and spec compliant. This package works isomorphically in browser and server-side JavaScript BrowserImport directly from the local path or a CDN import { parse } from 'path/to/csv/index.js'The minified version can be imported from import { parse } from 'path/to/csv/index.min.js' NodeInstall the package npm install @vanillaes/csvImport using the module path import { parse } from '@vanillaes/csv' Usage CSV.parse()Takes a string of CSV data and converts it to a 2 dimensional array of [entries][values] ArgumentsCSV.parse(csv, {options}, reviver(value, row, col)) : [entries][values] csv - the CSV string to parse options typed - infer types (default false) reviver1 - a custom function to modify the output (default (value) => value)1 Values for row and col are 1-based. Example const csv = ` "header1,header2,header3" "aaa,bbb,ccc" "zzz,yyy,xxx" `; const parsed = parse(csv) console.log(parsed); > [ > [ "header1", "header2", "header3" ], > [ "aaa", "bbb", "ccc" ], > [ "zzz", "yyy", "xxx" ] > ] CSV.stringify()Takes a 2 dimensional array of [entries][values] and converts them to CSV ArgumentsCSV.stringify(array, {options}, replacer(value, row, col)) : string array - the input array to stringify options eof - add a trailing newline at the end of file (default true) replacer1 - a custom function to modify the values (default (value) => value)1 Values for row and col are 1-based. Example const data = [ [ "header1", "header2", "header3" ], [ "aaa", "bbb", "ccc" ], [ "zzz", "yyy", "xxx" ] ]; const stringified = stringify(data) console.log(stringified); > "header1,header2,header3" > "aaa,bbb,ccc" > "zzz,yyy,xxx" TypescriptTypings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript. |
CopyRight 2018-2019 实验室设备网 版权所有 |